package com.dailyblue.project.estate.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @Auther:Liu
 * @Testname:ChartMemoryController
 * @Date:2025/9/22 14:34
 */
@RestController
@RequestMapping("/ollama_ai_memory")
public class ChartMemoryController {
    @Resource
    private ChatClient ollamaChatClient;
    private String message = "";

    @GetMapping(value = "/stream", produces = "text/html;charset=utf-8")
    Flux<String> stream(@RequestParam("message") String message) {
        this.message += message;
        return ollamaChatClient.prompt().user(this.message).stream().content();
    }


    @GetMapping(value = "/b", produces = "text/html;charset=utf-8")
    Flux<String> b(@RequestParam("question") String question, @RequestParam("userId") String userId) {
        return ollamaChatClient.prompt()
                .advisors(advisors ->
                        advisors.param("chat_memory_conversation_id", userId))
                .user(question).stream().content();
    }
}
